<?php require_once '../lib/Database.php';
$db = new Database();
Session::checkUser();

$userAssessments = $db->findRelation('assessment', 'user_id', Session::get('sid'));

?>
<?php include '../snippet/header.inc'; ?>
    <div class="header">
        Welcome to the dashboard <?php echo Session::get('sessionToken') . '!'; ?>
        <a href="?logout=1" class="right-float">Logout</a>
    </div>
    <div class="clear"></div>

    <div class="left-container">
        <form action="" method="POST" class="add-assmt">
            <label>Assessment</label>
            <input type="text" name="assessment" placeholder="Enter your Assessment">

            <label>Due Date</label>
            <input type="date" name="duedate">

            <label>Description</label>
            <textarea name="description" placeholder="Description" cols="30" rows="3"></textarea>

            <input type="hidden" name="user_id" value="<?php echo Session::get('sid'); ?>">

            <div class="clear"></div>
            <input type="submit" name="create" value="Create">
        </form>
    </div>
    <div class="right-container">

        <?php if ($userAssessments) : ?>
            <form class="assessment-form">
                <p><span class="completed"><input type="checkbox" checked="checked" disabled="disabled"> Completed</span> | <span><input type="checkbox" disabled="disabled"> Pending</span></p>
                <table>

                    <tr>
                        <th>Status</th>
                        <th>User</th>
                        <th>Assessment</th>
                        <th>Due Date</th>
                        <th>Description</th>
                    </tr>

                    <?php while ($assessment = mysql_fetch_object($userAssessments)) {
                        $user = $db->findById('users', $assessment->user_id);
                        ?>
                        <tr <?php echo $assessment->status == 1 ? ' class="completed"' : ''; ?> data-id="<?php echo $assessment->id; ?>" data-table="assessment">
                            <td class="center-align"><input type="checkbox" name="status" <?php echo $assessment->status == 1 ? ' checked="checked"' : ''; ?> value="<?php echo $assessment->status; ?>" ></td>
                            <td><?php echo $user->email; ?></td>
                            <td><?php echo $assessment->assessment; ?></td>
                            <td><?php echo $assessment->duedate; ?></td>
                            <td><?php echo $assessment->description; ?></td>
                        </tr>
                    <?php } ?>

                </table>
            </form>
        <?php endif; ?>
<?php include '../snippet/footer.inc' ?>
